home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 June: Reference Library / Dev.CD Jun 95 / Dev.CD Jun 95.toast / What's New? / New System Software Extensions / QuickDraw 3D ß / Programming / SampleCode / Modeller ƒ / Modeller_offscreen.c < prev    next >
Encoding:
Text File  |  1995-03-11  |  6.6 KB  |  267 lines  |  [TEXT/MPS ]

  1. //
  2. //        Offscreen.c
  3. //
  4. // To Do:
  5. //
  6. // This thing calls updateGWorld each time through, this is slow, fix
  7. //
  8.  
  9. #include "QD3D.h"
  10. #include "QD3DDrawContext.h"
  11. #include "QD3DShader.h"
  12. #include "QD3DGeometry.h"
  13. #include "QD3DStyle.h"
  14. #include "QD3DTransform.h"
  15. #include "QD3DMath.h"
  16.  
  17.  
  18. #include "Modeller_globals.h"
  19. #include "Modeller_prototypes.h"
  20. #include "Modeller_offscreen.h"
  21. #include "Modeller_windows.h"
  22.  
  23.  
  24.  
  25. TQ3Status DrawOffscreen(DocumentPtr theDocument)
  26.  
  27. {
  28. #ifndef PODIUM_APP    
  29.     TQ3DrawContextObject    drawCtx;
  30.  
  31.     Q3View_GetDrawContext(theDocument->theView, &drawCtx);
  32. #endif
  33.  
  34.     if( theDocument->documentGroup ) {
  35.  
  36.         RgnHandle    windowRgn, growRgn, clipRgn;
  37.         Rect        growRect;
  38.         TQ3Vector3D    globalScale;
  39.         TQ3Vector3D    globalTranslate;
  40.         
  41.         globalScale.x = globalScale.y = globalScale.z = theDocument->documentGroupScale;
  42.         globalTranslate = *(TQ3Vector3D *)&theDocument->documentGroupCenter;
  43.         Q3Vector3D_Scale(&globalTranslate, -1, &globalTranslate);
  44.     
  45.         SetPort(theDocument->theWindow);
  46.     
  47.         growRect = theDocument->theWindow->portRect;
  48.         growRect.top = growRect.bottom -15;
  49.         growRect.left = growRect.right -15;
  50.  
  51.         growRgn = NewRgn();
  52.         RectRgn(growRgn, &growRect);
  53.         
  54.         windowRgn = NewRgn();
  55.         RectRgn(windowRgn, &theDocument->theWindow->portRect);
  56.         
  57.         clipRgn = NewRgn();
  58.         DiffRgn(windowRgn, growRgn, clipRgn);
  59.         
  60.         SetClip(clipRgn);
  61.         
  62.         Q3View_StartRendering(theDocument->theView);
  63.         
  64.         do {                
  65.             TQ3SubdivisionStyleData        subData = {kQ3SubdivisionMethodConstant, 20, 20};
  66.         
  67.             Q3Shader_Submit(theDocument->illuminationShader, theDocument->theView);
  68.  
  69.             if( theDocument->light == kQ3True ) {
  70.                 Q3Object_Submit(theDocument->light1, theDocument->theView);
  71.                 Q3Object_Submit(theDocument->light2, theDocument->theView);
  72.                 Q3Object_Submit(theDocument->light3, theDocument->theView);
  73.             }
  74.         
  75.             if( theDocument->shaded == kQ3True )
  76.                 Q3Style_Submit(theDocument->backfacingStyle, theDocument->theView) ;
  77.                                 
  78.             Q3InterpolationStyle_Submit(theDocument->currentInterpolation,theDocument->theView);
  79.             
  80.             Q3SubdivisionStyle_Submit( &subData,theDocument->theView);
  81.             
  82.             Q3MatrixTransform_Submit( &theDocument->modelRotation, theDocument->theView);
  83.             Q3ScaleTransform_Submit(&globalScale, theDocument->theView);
  84.             Q3TranslateTransform_Submit(&globalTranslate, theDocument->theView);
  85.                         
  86.             Q3DisplayGroup_Submit(theDocument->documentGroup, theDocument->theView);
  87.             
  88.         } while (Q3View_EndRendering(theDocument->theView) == kQ3ViewStatusRetraverse);
  89.  
  90.         ClipRect(&theDocument->theWindow->portRect);
  91.         DisposeRgn(clipRgn);
  92.         DisposeRgn(windowRgn);
  93.         DisposeRgn(growRgn);
  94.     } else {
  95.     
  96.         Rect    theRect = theDocument->theWindow->portRect;
  97.  
  98. #ifndef PODIUM_APP
  99.         // only want to color the bg for modeller
  100.         RGBColor color = { 0xFFFF, 0xFFFF, 0xFFFF};
  101.         
  102.         color.red *= 0.8;
  103.         color.green *= 0.8;
  104.         color.blue *= 0.8;
  105.         
  106.         RGBBackColor(&color);
  107. #endif
  108.  
  109.         EraseRect( &theRect );
  110.         
  111. #ifndef PODIUM_APP
  112.         color.blue = color.green = color.red  =  0xFFFF;
  113.         RGBBackColor(&color);
  114. #endif
  115.  
  116.     }
  117.  
  118. #ifndef PODIUM_APP
  119.     Q3Object_Dispose( drawCtx );
  120. #else
  121. //    {
  122. //        // finally set up the mask
  123. //        CGrafPtr        savedPort ;
  124. //        GDHandle        savedGDH ;
  125. //        OSErr            theErr ;
  126. //        
  127. //        GetGWorld( &savedPort, &savedGDH ) ;
  128. //        SetGWorld( theDocument->maskOffscreen, nil ) ;
  129. //
  130. //
  131. //        CopyBits(&((GrafPtr) theDocument->geometriesOffscreen)->portBits,
  132. //                 &((GrafPtr) theDocument->maskOffscreen)->portBits,
  133. //                 &theDocument->geometriesOffscreen->portRect, 
  134. //                 &theDocument->maskOffscreen->portRect, 
  135. //                 srcCopy, 
  136. //                 0L);
  137. //                 
  138. //        theErr = QDError() ;
  139. //        SetGWorld( savedPort, savedGDH ) ;
  140. //    }
  141. #endif
  142.     
  143.     return(kQ3Success);
  144. }
  145.  
  146.  
  147.  
  148. void DrawOnscreen(DocumentPtr theDocument)
  149. {
  150. #if 0
  151.     Rect    srcRect, dstRect;
  152.     CGrafPtr    savedPort ;
  153.     GDHandle    savedDevice ;
  154.  
  155.     if(theDocument->theOffscreen == nil || theDocument->theOffscreen->offscreenWorld == nil) {
  156.         // Draw Offscreen will allocate them
  157.         if( DrawOffscreen(theDocument) == nil)
  158.             return;
  159.     }
  160.     
  161.     srcRect = theDocument->theOffscreen->offscreenWorld->portRect;
  162.     dstRect = theDocument->theWindow->portRect;
  163.     
  164.     if(!EqualRect(&theDocument->theOffscreen->offscreenWorld->portRect, &dstRect) ) {
  165.         /* Size of the window changed */
  166.         if( DrawOffscreen(theDocument) == nil)
  167.             return;
  168.     }
  169.  
  170.     srcRect.right  -= 15;
  171.     srcRect.bottom -= 15;
  172.  
  173.     dstRect.right  -= ;
  174.     dstRect.bottom -= ;
  175.     
  176.     GetGWorld(&savedPort,&savedDevice);
  177.     SetGWorld(theDocument->theOffscreen->windowPort, theDocument->theOffscreen->windowDevice);
  178.     
  179.     CopyBits(&((GrafPtr) theDocument->theOffscreen->offscreenWorld)->portBits,
  180.              (BitMap *) &(theDocument->theOffscreen->windowPort)->portPixMap,
  181.              &srcRect, &dstRect, srcCopy, 0L);
  182.         
  183.     SetGWorld( savedPort, savedDevice);
  184. #else
  185.     TQ3DrawContextObject        drawCtx;
  186.     RgnHandle                oldClip;
  187.     Rect                    contentRect;
  188.     GrafPtr                    savedPort ;
  189.     
  190.     GetPort( &savedPort ) ;
  191.     SetPort(theDocument->theWindow);
  192.     
  193.     oldClip = NewRgn();
  194.     GetClip(oldClip);
  195.  
  196.     contentRect = theDocument->theWindow->portRect;
  197. //    contentRect.bottom -= 15;
  198. //    contentRect.right -= 15;
  199.     ClipRect(&contentRect);
  200.  
  201. #ifndef PODIUM_APP
  202.     DoDrawGrowIcon(theDocument->theWindow);
  203. #else
  204.     
  205.     // copy the background picture to the offscreen buffer and 
  206.     // composite the geometry image
  207.     {
  208.         CGrafPtr        savedPort ;
  209.         GDHandle        savedGDH ;
  210.         OSErr            theErr ;
  211.         
  212.         GetGWorld( &savedPort, &savedGDH ) ;
  213.         SetGWorld( theDocument->screenBuffer, nil ) ;
  214.     
  215.         // this is the background picture
  216.         CopyBits(&((GrafPtr) theDocument->bgOffscreen)->portBits,
  217.                  &((GrafPtr) theDocument->screenBuffer)->portBits,
  218.                  &theDocument->bgOffscreen->portRect, 
  219.                  &theDocument->bgOffscreen->portRect, 
  220.                  srcCopy, 
  221.                  0L);
  222.     
  223.         // only copy from the offscreen if there is 
  224.         // a valid group in the document
  225.         
  226.         if( theDocument->documentGroup != NULL ) {
  227.             
  228.             // copy using the mask     
  229. //            CopyDeepMask(&((GrafPtr) theDocument->geometriesOffscreen)->portBits,
  230. //                         &((GrafPtr) theDocument->maskOffscreen)->portBits,
  231. //                         &((GrafPtr) theDocument->screenBuffer)->portBits,
  232. //                         &theDocument->geometriesOffscreen->portRect, 
  233. //                         &theDocument->maskOffscreen->portRect, 
  234. //                         &theDocument->dropArea, 
  235. //                         srcCopy, 
  236. //                         0L);
  237.                          
  238.                          
  239.             CopyBits(&((GrafPtr) theDocument->geometriesOffscreen)->portBits,
  240.                      &((GrafPtr) theDocument->screenBuffer)->portBits,
  241.                      &theDocument->geometriesOffscreen->portRect, 
  242.                      &theDocument->dropArea, 
  243.                      srcCopy | transparent, 
  244.                      0L);
  245.         }
  246.         SetGWorld( (CGrafPtr)theDocument->theWindow, nil ) ;
  247.         
  248.         CopyBits(&((GrafPtr) theDocument->screenBuffer)->portBits,
  249.                  &theDocument->theWindow->portBits,
  250.                  &theDocument->screenBuffer->portRect, 
  251.                  &theDocument->screenBuffer->portRect, 
  252.                  srcCopy, 
  253.                  0L);
  254.         
  255.         
  256.         SetGWorld( savedPort, savedGDH ) ;
  257.     }
  258.  
  259. #endif
  260.     
  261.  
  262.     SetClip(oldClip);
  263.     DisposeRgn(oldClip);
  264.     SetPort( savedPort ) ;
  265. #endif
  266. }
  267.